
#ifndef __RTCSCTIME_H__
#define __RTCSCTIME_H__

#include "RTCStype.h"
#include <sys/types.h>
#include <time.h>

//##ModelId=3AAC610C001F
class RTCS_CTime{
public:
	//##ModelId=3AAC610C005C
	RTCS_CTime()
	{
		m_time = time(0);
		ToStruct();
	}

	//##ModelId=3AAC610C005D
	RTCS_CTime(const time_t tsec)
	{
		m_time = tsec;
		ToStruct();
	}

	//##ModelId=3AAC610C005F
	RTCS_CTime( const RTCS_CTime& timeSrc )
	{
		m_time = timeSrc.m_time;
		ToStruct();
	}

	//##ModelId=3AAC610C0066
	RTCS_CTime( int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec)
	{
		m_tm.tm_year = nYear;
		m_tm.tm_mon = nMonth;
		m_tm.tm_mday = nDay;
		m_tm.tm_hour = nHour;
		m_tm.tm_min = nMin;
		m_tm.tm_sec = nSec;
		m_time = mktime(&m_tm);
		ToStruct();
	}

	//##ModelId=3AAC610C0053
	void Format(RTCS_CTstring &str)
	{
		char buf[80];
		sprintf(buf,"%04d-%02d-%02d %02d:%02d:%02d",m_tm.tm_year,m_tm.tm_mon,
			m_tm.tm_mday,m_tm.tm_hour,m_tm.tm_min,m_tm.tm_sec);
		str = buf;
	}

	//##ModelId=3AAC610C0052
	time_t GetTime()
	{	return m_time;	}

	//##ModelId=3AAC610C0051
	int GetYear()
	{	return m_tm.tm_year;	}

	//##ModelId=3AAC610C0049
	int GetMonth()
	{	return m_tm.tm_mon;	}

	//##ModelId=3AAC610C0048
	int GetDay()
	{	return m_tm.tm_mday;	}

	//##ModelId=3AAC610C0047
	int GetHour()
	{	return m_tm.tm_hour;	}

	//##ModelId=3AAC610C003F
	int GetMinute()
	{	return m_tm.tm_min;	}

	//##ModelId=3AAC610C003E
	int GetSecond()
	{	return m_tm.tm_sec;	}

	//##ModelId=3AAC610C003D
	int GetDayOfWeek()
	{	return m_tm.tm_wday;	}

private:

	//##ModelId=3AAC610C0035
	void ToStruct()
	{
		struct tm *ptm = localtime(&m_time);
		if(ptm)
		{
			memcpy(&m_tm,ptm,sizeof(m_tm));
			m_tm.tm_year += 1900;
			m_tm.tm_mon += 1;
		}
	}

private:
	//##ModelId=3AAC610C0034
	time_t	m_time;
	//##ModelId=3AAC610C0033
	struct tm m_tm;
};


#endif
